package com.digitalchina.lxnsy.activity.old;

import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.digitalchina.lxnsy.R;
import com.digitalchina.lxnsy.api.BusinessAuthentication;
import com.digitalchina.lxnsy.base.BaseActivity;
import com.digitalchina.lxnsy.constant.MSG;
import com.digitalchina.lxnsy.entity.AuditStatusVO;
import com.digitalchina.lxnsy.toolkit.FastJsonUtil;
import com.digitalchina.lxnsy.toolkit.GotoUtil;
import com.digitalchina.lxnsy.toolkit.StringUtil;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * ================================================
 * 项目名称：BigData
 * 类描述：
 * 包名：com.digitalchina.bigdata.activity
 * 创建人：郑皓
 * 创建时间：2017/7/21 15:06
 * 修改备注：
 * ================================================
 */
public class AuditStateActivity extends BaseActivity {
    @Bind(R.id.audit_tv_title)
    TextView auditTvTitle;
    @Bind(R.id.audit_tv_auditOpinion)
    TextView auditTvAuditOpinion;
    @Bind(R.id.audit_tv_update)
    TextView auditTvUpdate;
    @Bind(R.id.audit_iv_title_state)
    ImageView auditIvTitleState;

    private AuditStatusVO auditStatusVO;

    @Override
    public void setLayout() {
        setContentLayout(R.layout.activity_audit_state);
        setTitle("审核状态");
    }

    @Override
    public void initMember() {
        BusinessAuthentication.getAuditStatus(this, mHandler);
    }

    @Override
    public void addListener() {

    }

    @Override
    public void setHandler() {
        mHandler = new Handler() {
            @Override
            public void handleMessage(Message msg) {
                super.handleMessage(msg);
                switch (msg.what) {
                    case MSG.MSG_GET_AUDIT_STATUS_SUCCESS:
                        callBack(msg.obj);
                        break;
                    case MSG.MSG_GET_AUDIT_STATUS_FIELD:
                        showToast(msg.obj.toString());
                        break;
                }
            }
        };
    }

    @Override
    public void callBack(Object object) {

        auditStatusVO = FastJsonUtil.getBean(object.toString(), "", AuditStatusVO.class);

        if (auditStatusVO != null) {
            auditIvTitleState.setVisibility(View.VISIBLE);
            if (!auditStatusVO.getIsAudit().equals("1")) {
                switch (auditStatusVO.getIsAudit()) {
                    case "0":
                        auditTvTitle.setText("审核未通过");
                        auditIvTitleState.setImageResource(R.drawable.ic_audit_false);
                        auditTvAuditOpinion.setVisibility(View.VISIBLE);
                        auditTvUpdate.setVisibility(View.VISIBLE);
                        break;
                    case "1":
                        auditTvTitle.setText("审核通过");
                        auditIvTitleState.setImageResource(R.drawable.ic_pass);
                        auditTvAuditOpinion.setVisibility(View.VISIBLE);
                        auditTvUpdate.setVisibility(View.INVISIBLE);
                        break;
                    case "2":
                        auditTvTitle.setText("正在审核");
                        auditIvTitleState.setImageResource(R.drawable.ic_in_review);
                        auditTvUpdate.setVisibility(View.VISIBLE);
                        auditTvUpdate.setText("请等待工作人员审核");
                        break;
                    case "3":
                        auditTvTitle.setText("未提交审核");
                        auditIvTitleState.setImageResource(R.drawable.ic_audit_false);
                        auditTvUpdate.setVisibility(View.INVISIBLE);
                        break;
                    default:
                        auditTvTitle.setText("帐号状态异常");
                        auditIvTitleState.setImageResource(R.drawable.ic_audit_false);
                        auditTvUpdate.setVisibility(View.INVISIBLE);
                        break;
                }
            } else {
                switch (auditStatusVO.getIsChangeAudit()) {
                    case "0":
                        auditTvTitle.setText("审核未通过");
                        auditIvTitleState.setImageResource(R.drawable.ic_audit_false);
                        auditTvAuditOpinion.setVisibility(View.VISIBLE);
                        auditTvUpdate.setVisibility(View.VISIBLE);
                        break;
                    case "1":
                        auditTvTitle.setText("审核通过");
                        auditIvTitleState.setImageResource(R.drawable.ic_pass);
                        auditTvAuditOpinion.setVisibility(View.VISIBLE);
                        auditTvUpdate.setVisibility(View.INVISIBLE);
                        break;
                    case "2":
                        auditTvTitle.setText("正在审核");
                        auditIvTitleState.setImageResource(R.drawable.ic_in_review);
                        auditTvUpdate.setVisibility(View.VISIBLE);
                        auditTvUpdate.setText("请等待工作人员审核");
                        break;
                    case "3":
//                        auditTvTitle.setText("未提交审核");
                        auditTvTitle.setText("审核通过");
                        auditIvTitleState.setImageResource(R.drawable.ic_pass);
                        auditTvAuditOpinion.setVisibility(View.VISIBLE);
                        auditTvUpdate.setVisibility(View.INVISIBLE);
                        break;
                    default:
                        auditTvTitle.setText("帐号状态异常");
                        auditIvTitleState.setImageResource(R.drawable.ic_audit_false);
                        auditTvUpdate.setVisibility(View.INVISIBLE);
                        break;
                }
            }
            auditTvAuditOpinion.setText(StringUtil.isStrEmpty(auditStatusVO.getAuditOpinion()) ? "审核意见：暂无" : "审核意见：" + auditStatusVO.getAuditOpinion());
        } else
            showToast("获取失败");
    }

    @Override
    public void rightOnClick() {

    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @OnClick({R.id.audit_tv_auditOpinion, R.id.audit_tv_update})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.audit_tv_auditOpinion:
                break;
            case R.id.audit_tv_update:
                /**
                 * isAudit 0 审核未通过  1 审核通过  2 待审核  3 已注册 未提交
                 * isChangeAudit 0 审核未通过  1 审核通过  2 待审核  3 未修改
                 */
                if (auditStatusVO != null) {
                    if (!auditStatusVO.getIsAudit().equals("1")) {
                        //首次审核未通过
                        if (auditStatusVO.getIsAudit().equals("0")) {
                            GotoUtil.gotoActivity(AuditStateActivity.this, SaveExpertInfoActivity.class, true, "AuditStateActivity", "AuditStateActivity");
                        }
                    } else {
                        //首次审核未通过
                        if (auditStatusVO.getIsChangeAudit().equals("0")) {
                            GotoUtil.gotoActivity(AuditStateActivity.this, AuthenticationInfoActivity.class, true);
                        }
                    }
                }
                break;
        }
    }
}
